﻿using System;
using System.Collections.Generic;
using System.Text;
using rkShared.Serialization;

namespace rkShared
{
    [Serializable]
    public class Bullet : IBinarySerializable
    {
		private Vector3 position = new Vector3();
		private Vector3 destination = new Vector3();
		private Vector3 velocity = new Vector3();
		
		
		public void calculateVelocity()
		{
			velocity = destination - position;
			UMath.Normalize(ref velocity,velocity);
		}
		
		public Vector3 Position 
		{ 
			get{return position;}
			set{position = value;} 
		}
		public Vector3 Destination 
		{ 
			get{return destination;}
			set{destination = value;} 
		}
		public Vector3 Velocity 
		{ 
			get{return velocity;}
			set{velocity = value;} 
		}

        #region IBinarySerializable Members

        public void SerializeToDictionary(rkShared.BEncode.BEncodedDictionary dictionary)
        {
            dictionary.Add("p", this.position);
            dictionary.Add("d", this.destination);
            dictionary.Add("v", this.velocity);
        }
        public void DeserializeFromDictionary(rkShared.BEncode.BEncodedDictionary dict)
        {
            this.position = dict.GetIBinarySerializable<Vector3>("p");
            this.destination = dict.GetIBinarySerializable<Vector3>("d");
            this.velocity = dict.GetIBinarySerializable<Vector3>("v");

        }
        #endregion
    }
}
